/**
 * Created by ritamashin on 2017/11/17.
 */
import React, {PureComponent} from 'react'
import {View, Text, WebView} from 'react-native'
import * as actions from '../../../actions'
import store from '../../../store'
import {bindActionCreators} from 'redux'
import {connect} from 'react-redux'
import {COLOR} from '../../../config'


class GiftDetailWebView extends PureComponent{
    static navigationOptions = {
        title : '攻略详情',
        headerBackTitleStyle : {color : 'black'},
        headerStyle:{backgroundColor : 'white'}
    }



    static propTypes = {
        htmlString : React.PropTypes.string,
    };
    // 构造
      constructor(props) {
        super(props);
        let {giftItem} = this.props.navigation.state.params;
        store.dispatch(actions.getGiftItemDetailWithId(giftItem['id']));

      }

    render(){

        let {htmlString} = this.props;

        return <WebView html={htmlString}
                        onLoad={this.loadSuccess}
                        onError={this.loadError}
                        onLoadEnd={this.loadEnd}
                        onLoadStart={this.loadStart}
                        style={{padding : 10, backgroundColor: COLOR.themeBackGroundRedColor}}
        />
    }


    loadSuccess= () => {
        console.log('加载成功');
    };
    loadError = () => {
        console.log('加载失败');
    };
    loadEnd = () => {
        console.log('加载结束');
    }
    loadStart = () => {
        console.log('加载开始');
    }
}

function mapStateToProps(state) {
    let {giftDetail} = state;
    let {htmlString} = giftDetail;
    return {
        ...this.props,
        htmlString,
    }
}
function mapDispatchToProps(dispatch) {
    return bindActionCreators({}, dispatch);
}

export default connect(mapStateToProps, mapDispatchToProps)(GiftDetailWebView)